/*
 *  ScalaSwingSet
 *  Copyright (c) 2008 Andy Hicks. All rights reserved.
 *  http://www.scalalabs.net
 *
 *  This software is released under the terms of the Revised BSD License.
 *  There is NO WARRANTY. See the file LICENSE for the full text.
 */
package com.scalalabs.scalaswingset.utils


import java.awt.geom.RoundRectangle2D
import java.awt.Graphics2D
import scala.swing.{Panel, SequentialContainer}

class RoundedPanel(cornerRadius: Int) extends Panel with SequentialContainer.Wrapper {

  def this() = this(10)

  private val contentAreaFilled = true
  opaque = false

  @transient val roundBounds = new RoundRectangle2D.Float(0,0,0,0, cornerRadius, cornerRadius);

  override def paintComponent(g: java.awt.Graphics) {

    if ( contentAreaFilled ) {
        val g2 = g.asInstanceOf[Graphics2D]
        roundBounds.width = size.width
        roundBounds.height = size.height
        g2.setColor(background)
        g2.fill(roundBounds)
    }
    super.paintComponent(g)
  }
}
